<?php

class Core_Component_System_Controller_Backend_Dms_Entity {
    
    public function __construct() {
        $GLOBALS[RC]->getHelper()->setLocation('{system.system}', '{system.dms}');
    }

    public function indexAction() {
        $GLOBALS[RC]->getHelper()->setLocation('{system.label.entity_list}');
        $list = App::getModel('system/dms_entity')->getQuery()->fetch();
        return $GLOBALS[RC]->getHelper()->templateResult(array('list' => $list));
    }
    
    public function createAction() {
        $components = App::getModel('system/component')->getQuery()->fetch();
        $GLOBALS[RC]->getHelper()->setLocation('{system.label.create_entity}');
        return $GLOBALS[RC]->getHelper()->templateResult(array('components'=>$components));
    }

//    public function editAction($id = NULL) {
//        $result = $GLOBALS[RC]->getHelper()->templateResult(array(), '*/*/edit');
//        if (!is_null($id)) {
//            $model = App::loadModel('system/dms_entity', $id);
//            $GLOBALS[RC]->getHelper()->setLocation($model->getClassName());
//            $result->setModel($model);
//        }
//        return $result;
//    }

    public function saveAction(Core_Component_System_Model_Dms_Entity $model) {
        $model->merge()->validate()->save();
        $bus = App::getBusiness('system/dms_entity');
        if($model->getIsCreateFile()){
            $bus->createEntityFile($model);
        }
        if($model->getIsCreateTable()){
            $bus->createEntityTable($model);
        }
        return $GLOBALS[RC]->getHelper()->redirectResult('*/*/dms-entity/index', array('entityid'=>$model->getId()));
    }

}
